package HomeWork;

import static java.lang.Thread.sleep;

public class Main {

    public static void main(String[] args) {

        Test m = new Test();

        Thread w1 = new Thread(m, "窗口1");
        Thread w2 = new Thread(m, "窗口2");
        Thread w3 = new Thread(m, "窗口3");

        w1.start();
        w2.start();
        w3.start();

    }
}

class Test implements Runnable {
    private int n = 1;

    public void run() {
        while (n <21) {
            synchronized (this){
            System.out.println(Thread.currentThread().getName() + " : " +n+"号票" );
            n=n+1;
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        }
    }
}